package com.qk.management.controller;

import com.qk.result.PageResult;
import com.qk.result.Result;
import com.qk.dto.user.UserDTO;
import com.qk.entity.User;
import com.qk.management.service.UserService;
import com.qk.vo.user.UserVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/06 19:28
 * @Description: 用户管理控制器
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/users")
public class UserController {
    private final UserService userService;

    @PutMapping("")
    public Result updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result deleteUsers(@PathVariable("ids") List<Integer> ids) {
        userService.deleteUsers(ids);
        return Result.success();
    }

    @PostMapping
    public Result addUser(@RequestBody User user) {
        userService.addUser(user);
        return Result.success();
    }

    @GetMapping("/dept/{deptId}")
    public Result selectUserByDeptId(@PathVariable Integer deptId) {
        List<User> pageInfo  = userService.selectUserByDeptId(deptId);
        return Result.success(pageInfo);
    }

    @GetMapping("/role/{roleLabel}")
    public Result selectUserByRoleLabel(@PathVariable String roleLabel) {
        List<User> pageInfo  = userService.selectUserByRoleLabel(roleLabel);
        return Result.success(pageInfo);
    }

    @GetMapping("/{id}")
    public Result selectUserById(@PathVariable String id) {
        User user = userService.selectUserById(id);
        return Result.success(user);
    }

    @GetMapping("/list")
    public Result selectUserList() {
        List<User> pageInfo  = userService.selectUserList();
        return Result.success(pageInfo);
    }

    @GetMapping("")
    public Result selectUsersByPage(UserDTO userDto) {
        PageResult<UserVO> pageResult = userService.selectUsersByPage(userDto);
        return Result.success(pageResult);
    }

}
